import Vue from 'vue';
import App from './App';
import { router } from './router';
import axios from 'axios';

import { get, post } from './utils/http';
import { getCookie, setCookie, delCookie } from './utils/cookie';

import {
	Image as VanImage,
	Cell,
	CellGroup,
	Icon,
	Search,
	List,
	Toast,
	Button,
	Tab,
	Tabs,
	Col,
	Row,
	Calendar,
	Dialog,
	DropdownMenu,
	DropdownItem,
	Tag,
	Swipe,
	SwipeItem,
	GoodsAction,
	GoodsActionIcon,
	GoodsActionButton,
	Form,
	Field,
	Notify,
	Empty,
	Tabbar,
	TabbarItem,
	Switch,
	NoticeBar,
	PullRefresh,
	Sticky 
} from 'vant';

Vue.use(Sticky);
Vue.use(PullRefresh);
Vue.use(NoticeBar);
Vue.use(Switch);
Vue.use(Tabbar);
Vue.use(TabbarItem);
Vue.use(Empty);
Vue.use(Notify);
Vue.use(VanImage);
Vue.use(Tag);
Vue.use(Swipe);
Vue.use(Toast);
Vue.use(SwipeItem);
Vue.use(GoodsAction);
Vue.use(GoodsActionIcon);
Vue.use(GoodsActionButton);
Vue.use(Form);
Vue.use(Field);
Vue.use(Cell);
Vue.use(CellGroup); 
Vue.use(Icon);
Vue.use(Search);
Vue.use(List);
Vue.use(Toast);
Vue.use(Button) ;
Vue.use(Tab) ;
Vue.use(Tabs);
Vue.use(Col);
Vue.use(Row) ;
Vue.use(Calendar); 
Vue.use(Dialog);
Vue.use(DropdownMenu); 
Vue.use(DropdownItem);

Vue.prototype.$axios = axios;
Vue.prototype.$get = get;
Vue.prototype.$post = post;
Vue.prototype.$getCookie = getCookie;
Vue.prototype.$setCookie = setCookie;
Vue.prototype.$delCookie = delCookie;
//Vue.config.productionTip = false;
// 判断是开发环境还是发布
Vue.prototype.$url = process.env.NODE_ENV==="production"?"http://api.yanxusheng.cn":"/api";

//使用钩子函数对路由进行权限跳转
router.beforeEach((to, from, next) => {
    var role = getCookie('user_token');

    if (!role && to.fullPath != '/user_login' && to.fullPath != '/user_register') {
        next('/user_login');
    } else {
        // 简单的判断IE10及以下不进入富文本编辑器，该组件不兼容
        if (navigator.userAgent.indexOf('MSIE') > -1 && to.path === '/editor') {
            Vue.prototype.$alert('vue-quill-editor组件不兼容IE10及以下浏览器，请使用更高版本的浏览器查看', '浏览器不兼容通知', {
                confirmButtonText: '确定'
            });
        } else {
			const title = to.meta && to.meta.title;
			if (title) {
				document.title = title;
			}
            next();
        }
    }
})


new Vue({
  router,
  el: '#app',
  render: h => h(App)
});